package Test_1114;

import java.util.Arrays;

/**
 * Created with Intellij IDEA
 * Description:
 * User: 星辰
 */
public class MyStack {
    public int[] e;
    public int usedSize;
    public MyStack(int[] e) {
        this.e = e;
    }
    //入栈
    public void push(int val){
        //是否满了？扩容
        if(isFull()){
            this.e= Arrays.copyOf(e,2*e.length);
        }
        e[usedSize++]=val;
    }
    public boolean isFull(){
        return this.usedSize==e.length;
    }
    //出栈
    public int pop(){
        if(isEmpty()){
            throw new EmptyStackException();
        }
        int val=e[usedSize-1];
        usedSize--;
        return val;
    }
    public boolean isEmpty() throws EmptyStackException{
        return this.usedSize==0;
    }
    //栈顶
    public int peek(){
        if(isEmpty()){
            throw new EmptyStackException();
        }
        int val=e[usedSize-1];
        return val;
    }
}
